package chixing.day16;


import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;

public class InputStream_Demo {
    public static void main(String[] args) {
        FileInputStream is = null;
        //1.创建读取字节流
        try {
            is = new FileInputStream("E:\\2025-cx\\project\\PJ\\J01\\Javase\\Temp\\byte_hello.txt");
        } catch (FileNotFoundException e) {
            throw new RuntimeException(e);
        }
        //2.读数据
        byte[] byteArray = null;
        try {
            byteArray = new byte[is.available()];
        }catch (IOException e){
            e.printStackTrace();
        }
        int temp ;
        int i =0;
        try {
            while ((temp = is.read()) != -1){
                byteArray[i++] = (byte) temp;
            }
        }catch (IOException e){
            e.printStackTrace();
        }finally {//3.关闭字节流
            if (is != null) {
                try {
                    is.close();
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
        }
        String result = new String(byteArray);
        System.out.println(result);
    }
}
